<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Calendar"%>
<%@page import="wt.doc.WTDocument"%>
<%@page import="wt.fc.ReferenceFactory"%>
<%@page import="shmged.com.shlcm.utils.CmIBAHelper"%>
<%@page import="wt.lifecycle.LifeCycleTemplate"%>
<%@page import="wt.lifecycle.PhaseTemplate"%>
<%@page import="wt.lifecycle.State"%>
<%@page import="wt.lifecycle.LifeCycleTemplateMaster"%>
<%@page import="java.util.Vector"%>
<%@page import="wt.lifecycle.LifeCycleHelper"%>
<%@page import="wt.lifecycle.LifeCycleManaged"%>
<%@page import="wt.lifecycle.LifeCycleServerHelper"%>
<%@page import="shmged.com.shlcm.utils.CmCreateUtil"%>
<%@page import="shmged.com.shlcm.utils.CmCreateDocHelper"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.List"%><html >
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@page import="wt.httpgw.URLFactory"%>
<%@include file = "/shmged/jsp/com/shlcm/portal/main/head.jsp" %>
<head>
<title>修改费用报销</title>
<link rel="stylesheet" type="text/css" href="<%=baseUrl%>shmged/javascript/util/jquery-easyui-1.3.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=baseUrl%>shmged/javascript/util/jquery-easyui-1.3.3/themes/icon.css">
<script type="text/javascript">var pageBaseUrl = "<%=baseUrl%>";</script>
<script type="text/javascript" src="<%=baseUrl%>shmged/javascript/util/jquery-easyui-1.3.3/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="<%=baseUrl%>shmged/javascript/util/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<%=baseUrl%>shmged/jsp/com/shlcm/portal/js/main.js"></script>
<style type="text/css">
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
a:hover {
	text-decoration: none;
}
.current a {
            font-size: 20px;
        }

        .over {
            display: none;
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: #f5f5f5;
            opacity:0.5;
            z-index: 1000;
        }

        .layout {
            display: none;
            position: absolute;
            top: 40%;
            left: 40%;
            width: 20%;
            height: 20%;
            z-index: 1001;
            text-align:center;
        }
</style>

</head>
<body>
<%
	ReferenceFactory rf=new ReferenceFactory();
	String oid=request.getParameter("oid");
	WTDocument doc = (WTDocument)rf.getReference(oid).getObject();
	CmIBAHelper holder = new CmIBAHelper(doc);

	String sum= holder.getIBAValue("Sum");
	String amount= holder.getIBAValue("Amount");
	String rbType= holder.getIBAValue("RefeBursementType");
	String rbState= doc.getLifeCycleState().getDisplay();
	Calendar cal = Calendar.getInstance(); 
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	String cdate = sdf.format(cal.getTime()); 
	String time=holder.getIBAValue("Time").replace('/','-');
	time=time.substring(0,time.lastIndexOf("-")+3);
	String[] types=CmCreateUtil.getReimbursementType();
	String[] detailTypes=CmCreateUtil.getDetailType();
	List secondaryList=CmCreateDocHelper.getSecondaryFile(doc);
%>

<center>
<div style="margin:10px 0;"></div>
	<div  iconCls="icon-kms-related" title="创建费用报销" style="width:700px; height: 400px; padding: 5px;" id="update_browseCreateReimbursement"  >
		<center>
		<form method="post" enctype="multipart/form-data" name="updateRBForm" id="updateRBForm">
	 <div  class="easyui-panel" title="报销单" align="center">	
	
	 <input type="hidden" id="update_RBName" name="update_RBName" value="<%=doc.getName()%>"/>
	 
	 	
		<table  width="600px">
			
			<tr>
				<td align="right">项目名称:</td>
				<td align="left"><input class="easyui-validatebox" readonly="readonly" value="<%=holder.getIBAValue("ProjectName") %>"  type="text" id="update_ProjectName" name="update_ProjectName"></input></td>
				<td align="right">项目编号:</td>
				<td align="left"><input type="hidden" id="updateOid" name="updateOid" value="<%=oid %>"></input><input class="easyui-validatebox"  value="<%=holder.getIBAValue("ProjectNo") %>" type="text" id="update_ProjectNo" name="update_ProjectNo"></input></td>
			</tr>
			
			<tr>
				<td align="right">发票数:</td>
				<td align="left"><input class="easyui-numberbox" data-options="required:true" value="<%=holder.getIBAValue("InvoiceNum") %>"  type="text" id="update_InvoiceNum" name="update_InvoiceNum" onblur="numchecking('update_InvoiceNum')"></input>
					
				</td>
				<td align="right">报销日期:</td>
				<td align="left"><input  id="update_Time"   name="update_Time" value="<%=time%>"  class="easyui-datebox" data-options="formatter:myformatter,parser:myparser"></input><input type="hidden" id="update_RefeBursementLife" value="<%=holder.getIBAValue("RefeBursementLife")%>" name="update_RefeBursementLife"></input></td>
			</tr>
			
			<tr>
				<td align="right">单据类型:</td>
				<td align="left"><input type="text"  readonly="readonly" value="<%=holder.getIBAValue("RefeBursementType") %>" id="update_RefeBursementType"  name="update_RefeBursementType">
				</input>
				
				
				</td>
				<td align="right">付款方式:</td>
				<td align="left"><select id="update_PayMethod" name="update_PayMethod">
						<% if(holder.getIBAValue("PayMethod").equals("现金")){
						%>
							<option value="现金" selected="selected">现金</option>
						<option value="银行转账">银行转账</option>
						<%}else{
							%>
							<option value="现金">现金</option>
						<option value="银行转账"  selected="selected">银行转账</option>
							<% 
						}%>
					</select>
				</td>
			</tr>
			
			<tr>
				<td align="right">报销金额(小写):</td>
				<td align="left"><input  type="text"  id="add_update_Sum" name="add_update_Sum" disabled value="<%=sum %>"></input><input  type="hidden"  id="update_Sum" name="update_Sum"  value="<%=sum %>"></input></td>
				<td align="right">报销金额(大写):</td>
				<td align="left"><input type="text" disabled id="add_update_Amount" value="<%=amount %>" name="add_update_Amount"></input><input type="hidden"  id="update_Amount" value="<%=amount %>" name="update_Amount"></input></td>
			</tr>
		
		</table>
		</div>
		<div style="margin:10px 0;"></div>
		<div  class="easyui-panel" title="费用明细" align="center" style="height:440px" >
		<table width="600px" >
			<tr>
    			<td align="right" width="100px">费用类型:</td>
    			<td align="left">
    				<select id="update_detailType">
    					<%
    						for(int i=0;i<detailTypes.length;i++)
    						{
    							%>
    							<option value="<%=detailTypes[i] %>"><%=detailTypes[i] %></option>
    							<% 
    							
    						}
    					%>
    				</select>
    			</td>
    			<td align="right" width="100px">金额:</td>
    			<td align="left"><input  class="easyui-numberbox" data-options="required:true" type="text" id="update_detaiSum"></input></td>
    		</tr>
    		<tr>
    			<td align="right">用途:</td>
    			<td align="left"><input type="text" id="update_detaiTo" class="easyui-validatebox" required data-options="required:true"></input></td>
    			<td align="right">时间:</td>
    			<td align="left"><input type="text" id="update_detaiTime"  name="update_detaiTime" class="easyui-datebox" value="<%=cdate %>"   data-options="formatter:myformatter,parser:myparser"></input></td>
    		</tr>
			<tr>
				<td align="right">备注:</td>
				<td colspan="2" align="left"><input type="text" id="update_detaiDesc" size="35"></input></td>
				<td><input type="button" onclick="update_appendRBDetail()" value="增加明细"></input></td>
			</tr>
		</table>
		
		
		
		
		 	<table id="update_detailTable" class="easyui-datagrid" title="费用明细" style="width:600px;height:290px"
						data-options="rownumbers:true,singleSelect:true,toolbar:'#update_detailButton',onClickRow:onClickRow">
			</table>
				<div>  
				<div style="margin:10px 0;"></div>
		<table>
		<tr>
		<td align="right">附件：<input type="hidden"  id="isFalsedel" name="isFalsedel" value="false" ></input></td>

    			<td colspan="3" align="left">
    			
    			<% for(int i=0;i<secondaryList.size();i++){
				Map map=(Map)secondaryList.get(i);
			%>
			<div id="sceondary"><%=map.get("name") %>&nbsp; &nbsp;&nbsp;<a href="javaScript:void(0)"   onclick="delSec()">删除</a>	<br/></div>
			<%} %>
			<% if(secondaryList.size()>0)
			{
				%>
				<div><input type='file' id="newSceondary" style="display:none"  size=40 name='appendixFile"' id="appendixFile" /></div>
				<% 
			}else{
		%>
		<div><input type='file' id="newSceondary"   size=40 name='appendixFile"' id="appendixFile" /></div>
    			<%} %>
    			</td>
		
		</tr>
		</table>
		</div>	
		<div id="update_detailButton" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="update_removeDetail()">删除</a>
		</div>
		</div>
			</div>		
			<table>
				<tr>
					<td>
        			<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitUpdateRBForm()">保存</a>
	    			<a href="javascript:void(0)" class="easyui-linkbutton" onclick="closeUpdateRB()">关闭</a>
					</td>
				</tr>
			</table>
	</form>
		</center>
		
</div>

  <div id="over" class="over"></div>
  <div id="layout" class="layout"><img src="<%=baseUrl%>shmged/jsp/com/shlcm/reimbursement/loading.gif" /></div>

</center>
<script type="text/javascript">
var update_editIndex = undefined;
initUpdate_detailTable();
function showLoading()
{
    document.getElementById("over").style.display = "block";
    document.getElementById("layout").style.display = "block";
}


function delSec()
{
	document.getElementById("sceondary").style.display="none";
	document.getElementById("newSceondary").style.display="";	
	document.getElementById("isFalsedel").value="true";	
}


function onClickRow(index)
{
	update_editIndex=index;
}
function initUpdate_detailTable(){
	var oid="<%=oid%>";
	var url='<%=baseUrl%>shmged/jsp/com/shlcm/reimbursement/jspGetReimbursementDetialList.jsp';
	  $('#update_detailTable').datagrid({   
	      url:url,
	      queryParams:{oid:oid},
	      nowrap:false,
	      loadMsg:'正在加载数据，请稍等。。。',
		  fitColumns: true,
	      columns:[[   
	          {field:'detailType',title:'费用类型',width:40}, 
	          {field:'detailAmount',title:'金额',width:40},
	          {field:'detailTo',title:'用途',width:40},
	          {field:'detailTime',title:'时间',width:40},
	          {field:'detailDesc',title:'备注',width:160}
	      ]] 
	    }); 
}

function update_appendRBDetail()
{
	var update_detailType = document.getElementById("update_detailType");
	update_detailType=update_detailType.options[update_detailType.selectedIndex].value;
	var update_detaiSum=$("#update_detaiSum").val();
	var update_detaiTo=$("#update_detaiTo").val();
	var update_detaiDesc=$("#update_detaiDesc").val();
	var detaiTime="";
	var begin=document.getElementsByName("update_detaiTime");
	for(var i=0;i<begin.length;i++)
	{
		if(begin[i].value!="")
		{
			detaiTime=begin[i].value;
		}
		
	}
	var temp=""
	if(update_detaiSum==null||update_detaiSum=="")
	{
		temp="金额";
	}

	if(update_detaiTo==null||update_detaiTo=="")
	{
		if(temp.length>0)
		{
			temp=temp+"、";
		}
		temp=temp+"用途";
	}
	if(temp.length>0)
	{
		$.messager.alert('提示',"明细"+temp+"不能为空");
		return;
	}
	$('#update_detailTable').datagrid('appendRow',{detailType:update_detailType,detailAmount:update_detaiSum,detailTo:update_detaiTo,detailTime:detaiTime,detailDesc:update_detaiDesc});
	update_editIndex = $('#update_detailTable').datagrid('getRows').length-1;
	$('#update_detailTable').datagrid('selectRow', update_editIndex)
					.datagrid('beginEdit', update_editIndex);
	uodate_setSum();
}

function update_removeDetail(index)
{
		$('#update_detailTable').datagrid('cancelEdit', update_editIndex)
		.datagrid('deleteRow', update_editIndex);
		uodate_setSum();
}

function uodate_setSum()
{
	var rows = $("#update_detailTable").datagrid('getRows');
	var infos="";
	for(var i=0; i<rows.length; i++){
		infos=Number(infos)+Number(rows[i].detailAmount);
	}
	document.getElementById("add_update_Sum").value=infos;
	document.getElementById("add_update_Amount").value=convertCurrency(infos);
}

function submitUpdateRBForm()
{
	showLoading();

	document.getElementById("update_Sum").value=document.getElementById("add_update_Sum").value;
	document.getElementById("update_Amount").value=document.getElementById("add_update_Amount").value;
	
	$('#updateRBForm').submit();
}


	function initUpdateRBForm()
	{
		$("#updateRBForm").form({
			url:'<%=baseUrl%>shmged/jsp/com/shlcm/reimbursement/jspUpdateReimbursement.jsp',
			onSubmit:function (){
			},
			success:function (data){
				if(data.indexOf("ERROR") != -1){
					$.messager.alert('错误',data,'error');
				}else{
					var rows = $("#update_detailTable").datagrid('getRows');
					if(rows.length==0)
					{
						$.messager.alert('提示',"修改成功");
						window.location.href='<%=baseUrl %>shmged/jsp/com/shlcm/reimbursement/browseShowReimbursement.jsp?oid='+data;
					}else
					{
						updateDetail(data);
					}
					
					
				}
				hideProcessMsg("prince_process_ques");
			},
			onLoadError:function (){
				hideProcessMsg("prince_process_ques");
			}
		});
	}

	function updateDetail(oid)
	{

			var rows = $("#update_detailTable").datagrid('getRows');
			var infos="";
			for(var i=0; i<rows.length; i++){
				var desc="";
				if(rows[i].detailDesc==undefined||rows[i].detailDesc=="")
				{
					desc="";
				}else
				{
					desc=rows[i].detailDesc;
					
				}
				infos+=rows[i].detailType+"__"+rows[i].detailAmount+"__"+rows[i].detailTo+"__"+rows[i].detailTime+"__"+desc+"###";
			}
			
			var url="<%=baseUrl%>shmged/jsp/com/shlcm/reimbursement/jspCreateReimbursementDetail.jsp";
			var idata = {oid:oid,info:infos};
			  jQuery.post(url,idata,function (data){
				  window.location.href='<%=baseUrl %>shmged/jsp/com/shlcm/reimbursement/browseShowReimbursement.jsp?oid='+oid;
		        });
			
	}
	function closeUpdateRB()
	{
		window.close();
	}
	initUpdateRBForm();
</script>
</body>

</html>


